package com.heima.controller;

import com.heima.pojo.partner.Partner;
import com.heima.pojo.partner.PartnerPageResult;
import com.heima.pojo.partner.PartnerQueryParam;
import com.heima.service.PartnerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@Api(tags = "合作商管理")
@RequestMapping("/api/user-service/partner")
@RequiredArgsConstructor
public class PartnerController {
    private final PartnerService partnerService;
    /**
     * 新增合作商
     */
    @PostMapping
    @ApiOperation("新增合作商")
    public void addPartner(@RequestBody Partner partner) {
        log.info("新增合作商：{}", partner);
        partnerService.addPartner(partner);
    }
    /**
     * 合作商搜索
     */
    @GetMapping("/search")
    @ApiOperation("合作商搜索")
    public PartnerPageResult search(PartnerQueryParam param){
        PartnerPageResult result = partnerService.search(param);
        return result;
    }
    /**
     * 获取合作商详情
     */
    @ApiOperation("获取合作商详情")
    @GetMapping("/{id}")
    public Partner getById(@PathVariable Integer id){
        log.info("获取合作商详情：{}", id);
        Partner partner=partnerService.getById(id);
        return partner;
    }
    /**
     * 修改合作商
     */
    @ApiOperation("修改合作商")
    @PutMapping("/{id}")
    public void updatePartner(@PathVariable Integer id, @RequestBody Partner partner){
        log.info("修改合作商：{},{}",id, partner);
        partner.setId(id);
        partnerService.updatePartner(partner);
    }
    /**
     * 删除合作商
     */
    @ApiOperation("删除合作商")
    @DeleteMapping("/{id}")
    public void deletePartner(@PathVariable Integer id){
        log.info("删除合作商：{}", id);
        partnerService.deletePartner(id);
    }
}
